package applet;

import java.util.ArrayList;

import processing.core.PApplet;
import processing.core.PImage;

public class GenderPieChart{

	float xPos, yPos;
	float diameter;
	int elementCount;
	float sum;
	float startAngle, stopAngle;
	float[] number;
	int[] color;	
	PImage[] logo;
		
	GenderPieChart(float x, float y, float d, float m, float f) {
		xPos = x;
		yPos = y;
		diameter = d;
		elementCount = 2;
		number = new float[2];
		number[0] = m;
		number[1] = f;
		sum = m+f;
		PApplet.println("Sum is: "+sum);
		color =  new int[2];
		color[0] = GLOBAL.processing.color(0x43, 0x7C, 0xCF);
		color[1] = GLOBAL.processing.color(0xCF, 0x4C, 0x43);
		logo = new PImage[2];
		logo[0] = GLOBAL.processing.loadImage(GLOBAL.baseDir + "male.png");
		logo[1] = GLOBAL.processing.loadImage(GLOBAL.baseDir + "female.png");
				
	}
		
		
	void draw() {
//		    GLOBAL.processing.ellipseMode(PApplet.CENTER);
		startAngle = 0;
		GLOBAL.processing.imageMode(PApplet.CENTER);
		for(int i = 0; i< elementCount; i++) {
			stopAngle = startAngle + 2*PApplet.PI*number[i]/sum;
			GLOBAL.processing.fill(color[i]);
			GLOBAL.processing.arc(xPos+diameter*0.5f, yPos+diameter*0.5f, diameter, diameter, startAngle, stopAngle);
			GLOBAL.processing.image(logo[i], xPos+diameter*0.5f*(1+0.5f*PApplet.cos((startAngle+stopAngle)/2)), yPos+diameter*0.5f*(1+0.5f*PApplet.sin((startAngle+stopAngle)/2)), 15, 30);
			startAngle = stopAngle;
		}
	}
	
	void updateNumber(float m, float f) {
		number[0] = m;
		number[1] = f;
		sum = m+f;
	}
	
	void setPosition(float x, float y) {
		xPos = x;
		yPos = y;
	}
	
	void setDiameter(float d) {
		diameter = d;
	}
		
}
